/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.smarttv.querygraph.algorithm;

import edu.yonsei.iwb.smarttv.model.ConceptArc;
import edu.yonsei.iwb.smarttv.model.MArc;
import java.util.Enumeration;
import java.util.Vector;

/**
 *
 * @author DK
 */
    public class ShortestPathVectorCandidateSet extends Vector<ShortestPathSet> {
    
    public void orderByScore(){
//        ShortestPathVectorCandidateSet spvc = new ShortestPathVectorCandidateSet();
//        Vector<ShortestPathVector> v = new Vector<ShortestPathVector>();        
        double[] d = new double[this.size()];
        ShortestPathSet[] sp = new ShortestPathSet[this.size()];
        int index = 0;
        for (int i = 0; i < this.size(); i++) {
            d[index] = this.get(i).getScore();
            sp[index] = this.get(i);
            index++;            
        }                
        for (int i = 0; i < d.length-1; i++) {
            double temp;
            ShortestPathSet tempv;
            for (int j = 1; j < d.length; j++) {
                if(d[j-1] > d[j]){
                    temp = d[j-1];
                    d[j-1] = d[j];
                    d[j] = temp;
                    
                    tempv = sp[j-1];
                    sp[j-1] = sp[j];                    
                    sp[j] = tempv;
                }
            }
        }
        
        this.clear();
        for (int i = 0; i < sp.length; i++) {
            ShortestPathSet shortestPathVector = sp[i];
            this.add(shortestPathVector);            
        }
                
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        int i = 0;        
        for (int j = 0; j < this.size(); j++) {
            ShortestPathSet spv= this.get(j);            
            double temp = this.get(j).getScore();
            sb.append("Set of Shortest Path from Spaning Tree #" + i++ + " Score: " + temp + "Number of shortest path : "+spv.size()+"\n" + spv.toString());            
        }            
        return sb.toString();
    }
    
    public void printTemporalResult(){
        
        for (int i = 0; i < this.size(); i++) {
            
            ShortestPathSet spv = this.get(i);            
            Enumeration<ConceptArc> e = spv.keys();
            System.out.println("--------------------------------------------------");
            while(e.hasMoreElements()){
                ConceptArc ca = e.nextElement();                
                ShortestPath sp = spv.get(ca);
                System.out.println(ca.toString() + "   의 Shortest Path");
                for (int j = 0; j < sp.size(); j++) {
                    MArc marc = sp.get(j);
                    System.out.println(marc.toString());
                }                
            }            
            System.out.println("--------------------------------------------------");
        }
        
    }
    
    
}
